using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;

namespace TripleMatch
{
    public class DecorationCard : MonoBehaviour
    {
        [SerializeField] Button m_buttonClick;
        [SerializeField] Text m_textLeftCount;
        [SerializeField] Image m_imageIcon;

        private Action<int, DecorationCard> m_finishCallBack;

        public void InitDecorationData(int id, Sprite sprite , int leftCount, Action<int, DecorationCard> clickUse)
        { 
            m_finishCallBack = clickUse;
            m_imageIcon.sprite = sprite;
            m_textLeftCount.text = leftCount > 0 ? leftCount.ToString() : "";

            m_buttonClick.onClick.RemoveAllListeners();
            m_buttonClick.onClick.AddListener(() =>
            {
                m_finishCallBack?.Invoke(id, this);
            });
        }

        public void RefreshData(int leftCount)
        {
            m_textLeftCount.text = leftCount > 0 ? leftCount.ToString() : "";
        }
    }
}

